<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // 1. 创建新的数组原型对象
        var newPrototype = Object.create(Array.prototype);
        console.log(newPrototype); // {}

        // 2. 在自建的原型对象上写方法
        newPrototype.push = function(){
            // 1. 调用原数组的push方法
            Array.prototype.push.apply(this,arguments);
            // 2. 视图更新
            console.log('视图更新');
            // 3. 返回新数组的长度
            return this.length;
        }

        var arr = [1,2,3,4];
        if(arr instanceof Array){
            arr.__proto__ = newPrototype
        }
        arr.push(5);


        var arr2 = [1,2,3];
        arr2.push(4);
    </script>
</body>
</html>